package com.lx.yygh.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lx.yygh.common.result.Result;
import com.lx.yygh.model.order.OrderInfo;
import com.lx.yygh.service.OrderService;
import com.lx.yygh.user.client.PatientFeignClient;
import com.lx.yygh.vo.order.OrderQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author c先生
 * @date 2022年10月29日 下午 4:50:33
 * @describe
 */
@Api(tags = "订单模块")
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderApiController {

    @Autowired
    OrderService orderService;
    @Autowired
    PatientFeignClient patientFeignClient;

    @ApiOperation(value = "生成订单")
    @PostMapping("/auth/submitOrder/{scheduleId}/{patientId}")
    public Result submitOrder(@PathVariable("scheduleId")String scheduleId,
                              @PathVariable("patientId")Long patientId){
        Long b = orderService.saveOrder(scheduleId,patientId);
        return Result.ok(b);
    }

    @ApiOperation(value = "分页获取订单列表")
    @GetMapping("/auth/{page}/{limit}")
    public Result getPageList(@PathVariable("page")Integer page,
                              @PathVariable("limit")Integer limit,
                              OrderQueryVo orderQueryVo, HttpServletRequest request){
        IPage<OrderInfo> orderInfoIPage = orderService.getPageList(page,limit,orderQueryVo);
        return Result.ok(orderInfoIPage);
    }

    @ApiOperation(value = "获取订单状态列表")
    @GetMapping("/auth/getStatusList")
    public Result getStatusList(){
        List<Map<String, Object>> statusList = orderService.getStatusList();
        return Result.ok(statusList);
    }

    @ApiOperation(value = "获取订单的详细信息")
    @GetMapping("/auth/getOrders/{orderId}")
    public Result show(@PathVariable("orderId")Long id){
        OrderInfo orderInfo = orderService.getOrderInfoById(id);
        return Result.ok(orderInfo);
    }

    @ApiOperation(value = "取消预约，取消订单")
    @GetMapping("/auth/cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable("orderId")Long orderId){
        Boolean b = orderService.cancelOrder(orderId);
        return Result.ok(b);
    }
}
